﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CsharpTrainer.Model.Entities;
using Zeus.Thunder.Core;

namespace SharpTrainer.Linq
{
    class LinqOpTest : ITestCase
    {
        public void Run()
        {
            List<ContactInfo> contacts = new List<ContactInfo>();
            for (int i=0;i<20;i++)
            {
                contacts.Add(new ContactInfo
                {
                    ContactId = i+1,
                    FirstName = "Test",
                    LastName = "User" + (i+1),
                    Title = "Junior Developer",
                    Company = "Bleum"
                });
            }

            contacts.Add(new ContactInfo
            {
                ContactId = 1,
                FirstName = "David",
                LastName = "Gu",
                Title = "Senior Developer",
                Company = "Bleum"
            });
            contacts.Add(new ContactInfo
            {
                ContactId = 2,
                FirstName = "Jimmy",
                LastName = "Pan",
                Title = "Project Manager",
                Company = "Bleum"
            });

            Console.WriteLine("All Contacts Count: {0}", contacts.Count);
            Console.Write("Please Input Page Num: ");
            int page = Int32.Parse(Console.ReadLine());
            int pageSize = 5;
            List<ContactInfo> filteredContacts = contacts.Skip((page - 1) * pageSize).ToList();
            Console.WriteLine("After skip {0} page", page);
            Console.WriteLine("Record Count: {0}", filteredContacts.Count);
            Console.WriteLine("---------------------------------------------------");
            List<ContactInfo> pageContacts = contacts.Skip((page - 1) * pageSize).Take(pageSize).ToList();
            Console.WriteLine("Page Contacts:");
            Display(pageContacts);
        }

        private static void Display(List<ContactInfo> contacts)
        {
            foreach (ContactInfo contact in contacts)
                Console.WriteLine(contact);
        }
    }
}
